//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#if _MSC_VER > 1000
#pragma once
#endif

#if !defined(_WINTYPE_H_)
#define _WINTYPE_H_

#define __MSTYPES_H__
#define MIDL_INTERFACE CAR_INTERFACE

#ifndef STDAPICALLTYPE
#define STDAPICALLTYPE      __stdcall
#endif

#ifndef STDMETHODCALLTYPE
#define STDMETHODCALLTYPE   __stdcall
#endif

typedef int (STDAPICALLTYPE * FARPROC)();

#include <car.h>
_ELASTOS_NAMESPACE_USING

//==========================================================================
//                          windows macro define
//==========================================================================
#define MB_OK   0x01
#define PAGE_NOACCESS                     0x01
#define PAGE_READONLY                     0x02
#define PAGE_READWRITE                    0x04
#define PAGE_WRITECOPY                    0x08
#define PAGE_EXECUTE                      0x10
#define PAGE_EXECUTE_READ                 0x20
#define PAGE_EXECUTE_READWRITE            0x40
#define PAGE_EXECUTE_WRITECOPY            0x80
#define PAGE_GUARD                       0x100
#define PAGE_NOCACHE                     0x200

#define MEM_COMMIT                      0x1000
#define MEM_RESERVE                     0x2000
#define MEM_DECOMMIT                    0x4000
#define MEM_RELEASE                     0x8000
#define MEM_FREE                       0x10000
#define MEM_PRIVATE                    0x20000
#define MEM_MAPPED                     0x40000
#define MEM_RESET                      0x80000
#define MEM_TOP_DOWN                  0x100000
#define MEM_WRITE_WATCH               0x200000
#define MEM_PHYSICAL                  0x400000
#define MEM_4MB_PAGES               0x80000000

#define CREATE_SUSPENDED            0x00000004
#define CREATE_NEW_CONSOLE          0x00000010
#define CREATE_NEW_PROCESS_GROUP    0x00000200
#define CREATE_UNICODE_ENVIRONMENT  0x00000400
#define CREATE_SEPARATE_WOW_VDM     0x00000800
#define CREATE_SHARED_WOW_VDM       0x00001000
#define CREATE_FORCEDOS             0x00002000
#define CREATE_DEFAULT_ERROR_MODE   0x04000000
#define CREATE_NO_WINDOW            0x08000000
#define DEBUG_PROCESS               0x00000001
#define DEBUG_ONLY_THIS_PROCESS     0x00000002
#define DETACHED_PROCESS            0x00000008
#define PROCESS_CREATE_THREAD       (0x0002)
#define MAXLONG                     0x7fffffff
#define SYNCHRONIZE                 (0x00100000L)
#define STANDARD_RIGHTS_REQUIRED    (0x000F0000L)
#define PROCESS_ALL_ACCESS          (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE |\
                                     0xFFF)
#define THREAD_ALL_ACCESS           (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
                                     0x3FF)
#define PROCESS_TERMINATE           (0x0001)

#define STILL_ACTIVE                (0x00000103L)

#define ELACAL_E_WAIT_ABANDONED     ELASTOS_ERROR(0x001)
// A mutex object is not released by the thread that owned the mutex object
// before the owning thread terminated

#define ELACAL_E_THREAD_ABORTED      ELASTOS_ERROR(0x002)
// The thread is aborted

#define STATUS_WIN32_ERROR(u)        ((SCODE)((u)|0x80070000))
#define E_PROCESS_ABORTED            STATUS_WIN32_ERROR(1067)
#define E_SERVER_DIED                E_PROCESS_ABORTED

#define NORMAL_PRIORITY_CLASS        0x00000020
#define IDLE_PRIORITY_CLASS          0x00000040
#define HIGH_PRIORITY_CLASS          0x00000080
#define REALTIME_PRIORITY_CLASS      0x00000100

#define THREAD_BASE_PRIORITY_LOWRT   15  // value that gets a thread to
// LowRealtime-1
#define THREAD_BASE_PRIORITY_MAX     2   // maximum thread base priority boost
#define THREAD_BASE_PRIORITY_MIN     -2  // minimum thread base priority boost
#define THREAD_BASE_PRIORITY_IDLE    -15 // value that gets a thread to idle

#define THREAD_PRIORITY_TIME_CRITICAL   THREAD_BASE_PRIORITY_LOWRT
#define THREAD_PRIORITY_IDLE            THREAD_BASE_PRIORITY_IDLE
#define THREAD_PRIORITY_ERROR_RETURN    (MAXLONG)

#define THREAD_PRIORITY_LOWEST          THREAD_BASE_PRIORITY_MIN
#define THREAD_PRIORITY_BELOW_NORMAL    (THREAD_PRIORITY_LOWEST+1)
#define THREAD_PRIORITY_NORMAL          0
#define THREAD_PRIORITY_HIGHEST         THREAD_BASE_PRIORITY_MAX
#define THREAD_PRIORITY_ABOVE_NORMAL    (THREAD_PRIORITY_HIGHEST-1)
#define THREAD_PRIORITY_ERROR_RETURN    (MAXLONG)

#if !defined(INFINITE)
#define INFINITE                      -1     // Infinite timeout
#endif
#define WAIT_FAILED                   (DWORD)0xFFFFFFFF
#define STATUS_TIMEOUT                ((DWORD )0x00000102L)
#define WAIT_TIMEOUT                  STATUS_TIMEOUT
#define WAIT_ABANDONED                (DWORD)0x00000080
#define WAIT_IO_COMPLETION            (DWORD)0x000000C0L


#define MAX_PATH                      260
#define _MAX_LINE                     512
#define MAX_MODULE_NAME32             255
#define INVALID_HANDLE_VALUE          (HANDLE)-1
#define TH32CS_SNAPMODULE             0x00000008

#define DLL_PROCESS_DETACH            0
#define DLL_PROCESS_ATTACH            1
#define DLL_THREAD_ATTACH             2
#define DLL_THREAD_DETACH             3
#define DLL_PROCESS_DETACH_KERNEL     5
#define DLL_PROCESS_ATTACH_KERNEL     6
#define DLL_THREAD_ATTACH_KERNEL      7
#define DLL_THREAD_DETACH_KERNEL      8

#define STANDARD_RIGHTS_ALL           (0x001F0000L)
#define HKEY_CLASSES_ROOT             (( HKEY ) 0x80000000 )
#define REG_OPTION_NON_VOLATILE       (0x00000000L)   // Key is preserved
#define KEY_QUERY_VALUE               (0x0001)
#define KEY_SET_VALUE                 (0x0002)
#define KEY_CREATE_SUB_KEY            (0x0004)
#define KEY_ENUMERATE_SUB_KEYS        (0x0008)
#define KEY_NOTIFY                    (0x0010)
#define KEY_CREATE_LINK               (0x0020)

#define KEY_READ                      ((STANDARD_RIGHTS_READ       |\
                                        KEY_QUERY_VALUE            |\
                                        KEY_ENUMERATE_SUB_KEYS     |\
                                        KEY_NOTIFY)                 \
                                        &                           \
                                       (~SYNCHRONIZE))

#define KEY_WRITE                     ((STANDARD_RIGHTS_WRITE      |\
                                        KEY_SET_VALUE              |\
                                        KEY_CREATE_SUB_KEY)         \
                                        &                           \
                                       (~SYNCHRONIZE))

#define KEY_EXECUTE                   ((KEY_READ)                   \
                                        &                           \
                                       (~SYNCHRONIZE))

#define KEY_ALL_ACCESS                ((STANDARD_RIGHTS_ALL        |\
                                        KEY_QUERY_VALUE            |\
                                        KEY_SET_VALUE              |\
                                        KEY_CREATE_SUB_KEY         |\
                                        KEY_ENUMERATE_SUB_KEYS     |\
                                        KEY_NOTIFY                 |\
                                        KEY_CREATE_LINK)            \
                                        &                           \
                                       (~SYNCHRONIZE))

#define REG_SZ                         ( 1 )   // Unicode nul terminated string
#define WM_QUIT                        0x0012

#define ERROR_SUCCESS                   0
#define ERROR_ACCESS_DENIED             5
#define ERROR_INVALID_HANDLE            6
#define ERROR_SEM_TIMEOUT               121

#ifndef NOERROR
#define NOERROR                        0
#endif

#define MAKE_SCODE(sev,fac,code)     ((SCODE) (((unsigned long)(sev)<<31) |\
                                     ((unsigned long)(fac)<<16)           |\
                                     ((unsigned long)(code))) )

#define SELFREG_E_FIRST                MAKE_SCODE(SEVERITY_ERROR,          \
                                       FACILITY_ITF, 0x0200)
#define SELFREG_E_CLASS                (SELFREG_E_FIRST+1)

#define PROCESS_QUERY_INFORMATION (0x0400)
#define PROCESS_VM_READ           (0x0010)

#define INVALID_SET_FILE_POINTER  ((DWORD)-1)

#define FILE_BEGIN           0
#define FILE_CURRENT         1
#define FILE_END             2

#ifndef _REFIID_DEFINED
#define _REFIID_DEFINED
#define REFIID const IID &
#endif

//==========================================================================
//              windows struct define and type define
//==========================================================================

typedef char CHAR;
typedef CHAR *PSTR;
typedef const CHAR *PCSTR;
typedef wchar_t WCHAR;
typedef WCHAR OLECHAR;
typedef WCHAR *BSTR;
typedef WCHAR *PWSTR;
typedef const WCHAR *PCWSTR;

typedef char TCHAR;
//typedef wchar_t wchar_t;
typedef wchar_t *LPWSTR;
typedef const wchar_t *LPCWCH, *PCWCH;
typedef const wchar_t *LPCWSTR;
typedef wchar_t *PTSTR, *LPTSTR;
typedef wchar_t*     LPOLESTR;
typedef char *PCHAR;

typedef byte  BYTE;
typedef byte* LPBYTE;
typedef const wchar_t *LPCTSTR;
typedef void  VOID;
typedef void* LPVOID;
typedef void* PVOID;
typedef const void* LPCVOID;
//typedef IUnknown *LPUNKNOWN;
typedef UInt32* LPDWORD;
typedef CONST char *LPCSTR, *PCSTR;
typedef char *LPSTR, *PSTR;
typedef unsigned char       UCHAR;

typedef unsigned short WORD;
typedef WORD *PWORD;
typedef unsigned long DWORD;
typedef DWORD *PDWORD;

typedef void *HRSRC;
typedef void *HGLOBAL;
typedef void *HANDLE;
typedef const void *PCVOID;
typedef void *HMODULE;
typedef void *HWND;
typedef void *HGLRC;

typedef int      INT;
typedef int      INT32;
typedef unsigned short    USHORT;
typedef unsigned int      UINT;
typedef unsigned int      UINT32;
typedef unsigned short    UINT16;
typedef unsigned char     UINT8;
typedef long  HRESULT;
typedef int   BOOL;
typedef unsigned long     ULONG;
typedef long              LONG;
typedef long             *PLONG;
typedef unsigned long     ULONG;
typedef ULONG             *PULONG;
#ifdef _GNUC
typedef unsigned long long  UINT64;
typedef unsigned long long  ULONGLONG;
typedef long long           LONGLONG;
#else
typedef unsigned __int64  UINT64;
typedef __uint64          ULONGLONG;
typedef __int64           LONGLONG;
#endif
typedef unsigned long    OID;
typedef unsigned int     SIZE_T;

typedef unsigned int WPARAM;
typedef long LPARAM;
typedef long LRESULT;

typedef EMuid CLSID;

typedef union _LARGE_INTEGER {
    struct {
        DWORD LowPart;
        LONG HighPart;
    };
    struct {
        DWORD LowPart;
        LONG HighPart;
    } u;
    LONGLONG QuadPart;
} LARGE_INTEGER;
typedef LARGE_INTEGER *PLARGE_INTEGER;

typedef union _ULARGE_INTEGER {
    struct {
        DWORD LowPart;
        DWORD HighPart;
    };
    struct {
        DWORD LowPart;
        DWORD HighPart;
    } u;
    ULONGLONG QuadPart;
} ULARGE_INTEGER;
typedef ULARGE_INTEGER *PULARGE_INTEGER;

typedef struct tagRECT
{
    LONG    left;
    LONG    top;
    LONG    right;
    LONG    bottom;
} RECT, *PRECT, *LPRECT;

typedef struct _SYSTEMTIME {
    WORD wYear;
    WORD wMonth;
    WORD wDayOfWeek;
    WORD wDay;
    WORD wHour;
    WORD wMinute;
    WORD wSecond;
    WORD wMilliseconds;
} SYSTEMTIME;
typedef SYSTEMTIME *PSYSTEMTIME, *LPSYSTEMTIME;

typedef enum tagCLSCTX {
    CLSCTX_INPROC_SERVER     = 0x1,
    CLSCTX_INPROC_HANDLER    = 0x2,
    CLSCTX_LOCAL_SERVER      = 0x4,
    CLSCTX_INPROC_SERVER16   = 0x8,
    CLSCTX_REMOTE_SERVER     = 0x10,
    CLSCTX_INPROC_HANDLER16  = 0x20,
    CLSCTX_INPROC_SERVERX86  = 0x40,
    CLSCTX_INPROC_HANDLERX86 = 0x80,
    CLSCTX_ESERVER_HANDLER   = 0x100
    }CLSCTX;
#define CLSCTX_SERVER  (CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER|CLSCTX_REMOTE_SERVER)

typedef enum tagREGCLS
{
    REGCLS_SINGLEUSE = 0,       // class object only generates one instance
    REGCLS_MULTIPLEUSE = 1,     // same class object genereates multiple inst.
                                // and local automatically goes into inproc tbl.
    REGCLS_MULTI_SEPARATE = 2,  // multiple use, but separate control over each
                                // context.
    REGCLS_SUSPENDED      = 4,  // register is as suspended, will be activated
                                // when app calls CoResumeClassObjects
    REGCLS_SURROGATE      = 8   // must be used when a surrogate process
                                // is registering a class object that will be
                                // loaded in the surrogate
} REGCLS;

typedef struct _STARTUPINFOW {
    DWORD   cb;
    LPWSTR  lpReserved;
    LPWSTR  lpDesktop;
    LPWSTR  lpTitle;
    DWORD   dwX;
    DWORD   dwY;
    DWORD   dwXSize;
    DWORD   dwYSize;
    DWORD   dwXCountChars;
    DWORD   dwYCountChars;
    DWORD   dwFillAttribute;
    DWORD   dwFlags;
    WORD    wShowWindow;
    WORD    cbReserved2;
    LPBYTE  lpReserved2;
    HANDLE  hStdInput;
    HANDLE  hStdOutput;
    HANDLE  hStdError;
} STARTUPINFOW, *LPSTARTUPINFOW;
typedef LPSTARTUPINFOW LPSTARTUPINFO;

typedef struct _PROCESS_INFORMATION {
    HANDLE hProcess;
    HANDLE hThread;
    DWORD dwProcessId;
    DWORD dwThreadId;
} PROCESS_INFORMATION, *PPROCESS_INFORMATION, *LPPROCESS_INFORMATION;

typedef struct _SECURITY_ATTRIBUTES {
  DWORD  nLength;
  LPVOID lpSecurityDescriptor;
  BOOL   bInheritHandle;
} SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES;
typedef struct _SECURITY_ATTRIBUTES* LPSECURITY_ATTRIBUTES;

typedef DWORD (__stdcall *LPTHREAD_START_ROUTINE)(void*);

#ifndef _FILETIME_
#define _FILETIME_
typedef struct tagFILETIME
{
    DWORD dwLowDateTime;
    DWORD dwHighDateTime;
} FILETIME, *LPFILETIME;
#endif		/* _FILETIME */

typedef struct _MEMORY_BASIC_INFORMATION {
  PVoid BaseAddress;
  PVoid AllocationBase;
  DWORD AllocationProtect;
  SIZE_T RegionSize;
  DWORD State;
  DWORD Protect;
  DWORD Type;
} MEMORY_BASIC_INFORMATION, *PMEMORY_BASIC_INFORMATION;

typedef DWORD *DWORD_PTR;
typedef struct _SYSTEM_INFO {
  union {
    DWORD  dwOemId;
    struct {
      WORD wProcessorArchitecture;
      WORD wReserved;
    };
  };
  DWORD  dwPageSize;
  LPVOID lpMinimumApplicationAddress;
  LPVOID lpMaximumApplicationAddress;
  DWORD_PTR dwActiveProcessorMask;
  DWORD dwNumberOfProcessors;
  DWORD dwProcessorType;
  DWORD dwAllocationGranularity;
  WORD wProcessorLevel;
  WORD wProcessorRevision;
} SYSTEM_INFO;
typedef SYSTEM_INFO *LPSYSTEM_INFO;

typedef DWORD ACCESS_MASK;
typedef ACCESS_MASK REGSAM;
typedef struct tagMODULEENTRY32 {
  DWORD   dwSize;
  DWORD   th32ModuleID;
  DWORD   th32ProcessID;
  DWORD   GlblcntUsage;
  DWORD   ProccntUsage;
  BYTE  * modBaseAddr;
  DWORD   modBaseSize;
  HMODULE hModule;
  TCHAR   szModule[MAX_MODULE_NAME32 + 1];
  TCHAR   szExePath[MAX_PATH];
} MODULEENTRY32;
typedef MODULEENTRY32 *PMODULEENTRY32, *LPMODULEENTRY32;

typedef struct _MODULEINFO {
    LPVOID lpBaseOfDll;
    DWORD SizeOfImage;
    LPVOID EntryPoint;
} MODULEINFO, *LPMODULEINFO;

typedef struct _LIST_ENTRY {
   struct _LIST_ENTRY *Flink;
   struct _LIST_ENTRY *Blink;
} LIST_ENTRY;
typedef LIST_ENTRY *PLIST_ENTRY;

typedef struct _RTL_CRITICAL_SECTION_DEBUG {
    WORD   Type;
    WORD   CreatorBackTraceIndex;
    struct _RTL_CRITICAL_SECTION *CriticalSection;
    LIST_ENTRY ProcessLocksList;
    DWORD EntryCount;
    DWORD ContentionCount;
    DWORD Spare[ 2 ];
}RTL_CRITICAL_SECTION_DEBUG,*PRTL_CRITICAL_SECTION_DEBUG;

typedef RTL_CRITICAL_SECTION_DEBUG RTL_RESOURCE_DEBUG, *PRTL_RESOURCE_DEBUG;

#define RTL_CRITSECT_TYPE 0
#define RTL_RESOURCE_TYPE 1

typedef struct _RTL_CRITICAL_SECTION {
    PRTL_CRITICAL_SECTION_DEBUG DebugInfo;
    LONG LockCount;
    LONG RecursionCount;
    HANDLE OwningThread;        // from the thread's ClientId->UniqueThread
    HANDLE LockSemaphore;
    DWORD SpinCount;
}RTL_CRITICAL_SECTION, *PRTL_CRITICAL_SECTION, *LPRTL_CRITICAL_SECTION;

typedef struct _OVERLAPPED {
    DWORD   Internal;
    DWORD   InternalHigh;
    DWORD   Offset;
    DWORD   OffsetHigh;
    HANDLE  hEvent;
} OVERLAPPED, *LPOVERLAPPED;

typedef struct _PROCESS_MEMORY_COUNTERS {
    DWORD cb;
    DWORD PageFaultCount;
    SIZE_T PeakWorkingSetSize;
    SIZE_T WorkingSetSize;
    SIZE_T QuotaPeakPagedPoolUsage;
    SIZE_T QuotaPagedPoolUsage;
    SIZE_T QuotaPeakNonPagedPoolUsage;
    SIZE_T QuotaNonPagedPoolUsage;
    SIZE_T PagefileUsage;
    SIZE_T PeakPagefileUsage;
} PROCESS_MEMORY_COUNTERS, *PPROCESS_MEMORY_COUNTERS;

typedef struct _WIN32_FIND_DATAW {
    DWORD dwFileAttributes;
    FILETIME ftCreationTime;
    FILETIME ftLastAccessTime;
    FILETIME ftLastWriteTime;
    DWORD nFileSizeHigh;
    DWORD nFileSizeLow;
    DWORD dwOID;
    wchar_t   cFileName[ MAX_PATH ];
} WIN32_FIND_DATAW, *PWIN32_FIND_DATAW, *LPWIN32_FIND_DATAW;

typedef struct _MEMORYSTATUS {
    DWORD dwLength;
    DWORD dwMemoryLoad;
    SIZE_T dwTotalPhys;
    SIZE_T dwAvailPhys;
    SIZE_T dwTotalPageFile;
    SIZE_T dwAvailPageFile;
    SIZE_T dwTotalVirtual;
    SIZE_T dwAvailVirtual;
} MEMORYSTATUS,  *LPMEMORYSTATUS;

typedef struct tagPOINT
{
    LONG  x;
    LONG  y;
} POINT, *PPOINT;

// PE file format

#define IMAGE_DOS_SIGNATURE                 0x5A4D      // MZ
#define IMAGE_OS2_SIGNATURE                 0x454E      // NE
#define IMAGE_OS2_SIGNATURE_LE              0x454C      // LE
#define IMAGE_VXD_SIGNATURE                 0x454C      // LE
#define IMAGE_NT_SIGNATURE                  0x00004550  // PE00

typedef struct _IMAGE_DOS_HEADER {      // DOS .EXE header
    WORD   e_magic;                     // Magic number
    WORD   e_cblp;                      // Bytes on last page of file
    WORD   e_cp;                        // Pages in file
    WORD   e_crlc;                      // Relocations
    WORD   e_cparhdr;                   // Size of header in paragraphs
    WORD   e_minalloc;                  // Minimum extra paragraphs needed
    WORD   e_maxalloc;                  // Maximum extra paragraphs needed
    WORD   e_ss;                        // Initial (relative) SS value
    WORD   e_sp;                        // Initial SP value
    WORD   e_csum;                      // Checksum
    WORD   e_ip;                        // Initial IP value
    WORD   e_cs;                        // Initial (relative) CS value
    WORD   e_lfarlc;                    // File address of relocation table
    WORD   e_ovno;                      // Overlay number
    WORD   e_res[4];                    // Reserved words
    WORD   e_oemid;                     // OEM identifier (for e_oeminfo)
    WORD   e_oeminfo;                   // OEM information; e_oemid specific
    WORD   e_res2[10];                  // Reserved words
    LONG   e_lfanew;                    // File address of new exe header
  } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;

typedef struct _IMAGE_FILE_HEADER {
    WORD    Machine;
    WORD    NumberOfSections;
    DWORD   TimeDateStamp;
    DWORD   PointerToSymbolTable;
    DWORD   NumberOfSymbols;
    WORD    SizeOfOptionalHeader;
    WORD    Characteristics;
} IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;

#define IMAGE_SIZEOF_FILE_HEADER             20

#define IMAGE_FILE_RELOCS_STRIPPED           0x0001  // Relocation info stripped from file.
#define IMAGE_FILE_EXECUTABLE_IMAGE          0x0002  // File is executable  (i.e. no unresolved externel references).
#define IMAGE_FILE_LINE_NUMS_STRIPPED        0x0004  // Line nunbers stripped from file.
#define IMAGE_FILE_LOCAL_SYMS_STRIPPED       0x0008  // Local symbols stripped from file.
#define IMAGE_FILE_AGGRESIVE_WS_TRIM         0x0010  // Agressively trim working set
#define IMAGE_FILE_LARGE_ADDRESS_AWARE       0x0020  // App can handle >2gb addresses
#define IMAGE_FILE_BYTES_REVERSED_LO         0x0080  // Bytes of machine word are reversed.
#define IMAGE_FILE_32BIT_MACHINE             0x0100  // 32 bit word machine.
#define IMAGE_FILE_DEBUG_STRIPPED            0x0200  // Debugging info stripped from file in .DBG file
#define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP   0x0400  // If Image is on removable media, copy and run from the swap file.
#define IMAGE_FILE_NET_RUN_FROM_SWAP         0x0800  // If Image is on Net, copy and run from the swap file.
#define IMAGE_FILE_SYSTEM                    0x1000  // System File.
#define IMAGE_FILE_DLL                       0x2000  // File is a DLL.
#define IMAGE_FILE_UP_SYSTEM_ONLY            0x4000  // File should only be run on a UP machine
#define IMAGE_FILE_BYTES_REVERSED_HI         0x8000  // Bytes of machine word are reversed.

#define IMAGE_FILE_MACHINE_UNKNOWN           0
#define IMAGE_FILE_MACHINE_I386              0x014c  // Intel 386.
#define IMAGE_FILE_MACHINE_R3000             0x0162  // MIPS little-endian, 0x160 big-endian
#define IMAGE_FILE_MACHINE_R4000             0x0166  // MIPS little-endian
#define IMAGE_FILE_MACHINE_R10000            0x0168  // MIPS little-endian
#define IMAGE_FILE_MACHINE_WCEMIPSV2         0x0169  // MIPS little-endian WCE v2
#define IMAGE_FILE_MACHINE_ALPHA             0x0184  // Alpha_AXP
#define IMAGE_FILE_MACHINE_SH3               0x01a2  // SH3 little-endian
#define IMAGE_FILE_MACHINE_SH3DSP            0x01a3
#define IMAGE_FILE_MACHINE_SH3E              0x01a4  // SH3E little-endian
#define IMAGE_FILE_MACHINE_SH4               0x01a6  // SH4 little-endian
#define IMAGE_FILE_MACHINE_SH5               0x01a8  // SH5
#define IMAGE_FILE_MACHINE_ARM               0x01c0  // ARM Little-Endian
#define IMAGE_FILE_MACHINE_THUMB             0x01c2
#define IMAGE_FILE_MACHINE_AM33              0x01d3
#define IMAGE_FILE_MACHINE_POWERPC           0x01F0  // IBM PowerPC Little-Endian
#define IMAGE_FILE_MACHINE_POWERPCFP         0x01f1
#define IMAGE_FILE_MACHINE_IA64              0x0200  // Intel 64
#define IMAGE_FILE_MACHINE_MIPS16            0x0266  // MIPS
#define IMAGE_FILE_MACHINE_ALPHA64           0x0284  // ALPHA64
#define IMAGE_FILE_MACHINE_MIPSFPU           0x0366  // MIPS
#define IMAGE_FILE_MACHINE_MIPSFPU16         0x0466  // MIPS
#define IMAGE_FILE_MACHINE_AXP64             IMAGE_FILE_MACHINE_ALPHA64
#define IMAGE_FILE_MACHINE_TRICORE           0x0520  // Infineon
#define IMAGE_FILE_MACHINE_CEF               0x0CEF
#define IMAGE_FILE_MACHINE_EBC               0x0EBC  // EFI Byte Code
#define IMAGE_FILE_MACHINE_AMD64             0x8664  // AMD64 (K8)
#define IMAGE_FILE_MACHINE_M32R              0x9041  // M32R little-endian
#define IMAGE_FILE_MACHINE_CEE               0xC0EE

//
// Directory format.
//

typedef struct _IMAGE_DATA_DIRECTORY {
    DWORD   VirtualAddress;
    DWORD   Size;
} IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;

#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES    16

//
// Optional header format.
//

typedef struct _IMAGE_OPTIONAL_HEADER {
    //
    // Standard fields.
    //

    WORD    Magic;
    BYTE    MajorLinkerVersion;
    BYTE    MinorLinkerVersion;
    DWORD   SizeOfCode;
    DWORD   SizeOfInitializedData;
    DWORD   SizeOfUninitializedData;
    DWORD   AddressOfEntryPoint;
    DWORD   BaseOfCode;
    DWORD   BaseOfData;

    //
    // NT additional fields.
    //

    DWORD   ImageBase;
    DWORD   SectionAlignment;
    DWORD   FileAlignment;
    WORD    MajorOperatingSystemVersion;
    WORD    MinorOperatingSystemVersion;
    WORD    MajorImageVersion;
    WORD    MinorImageVersion;
    WORD    MajorSubsystemVersion;
    WORD    MinorSubsystemVersion;
    DWORD   Win32VersionValue;
    DWORD   SizeOfImage;
    DWORD   SizeOfHeaders;
    DWORD   CheckSum;
    WORD    Subsystem;
    WORD    DllCharacteristics;
    DWORD   SizeOfStackReserve;
    DWORD   SizeOfStackCommit;
    DWORD   SizeOfHeapReserve;
    DWORD   SizeOfHeapCommit;
    DWORD   LoaderFlags;
    DWORD   NumberOfRvaAndSizes;
    IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
} IMAGE_OPTIONAL_HEADER, *PIMAGE_OPTIONAL_HEADER;

// IMAGE_FIRST_SECTION doesn't need 32/64 versions since the file header is the same either way.

#define IMAGE_FIRST_SECTION( ntheader ) ((PIMAGE_SECTION_HEADER)        \
    ((ULONG_PTR)ntheader +                                              \
     FIELD_OFFSET( IMAGE_NT_HEADERS, OptionalHeader ) +                 \
     ((PIMAGE_NT_HEADERS)(ntheader))->FileHeader.SizeOfOptionalHeader   \
    ))

// Subsystem Values

#define IMAGE_SUBSYSTEM_UNKNOWN              0   // Unknown subsystem.
#define IMAGE_SUBSYSTEM_NATIVE               1   // Image doesn't require a subsystem.
#define IMAGE_SUBSYSTEM_WINDOWS_GUI          2   // Image runs in the Windows GUI subsystem.
#define IMAGE_SUBSYSTEM_WINDOWS_CUI          3   // Image runs in the Windows character subsystem.
#define IMAGE_SUBSYSTEM_OS2_CUI              5   // image runs in the OS/2 character subsystem.
#define IMAGE_SUBSYSTEM_POSIX_CUI            7   // image runs in the Posix character subsystem.
#define IMAGE_SUBSYSTEM_NATIVE_WINDOWS       8   // image is a native Win9x driver.
#define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI       9   // Image runs in the Windows CE subsystem.
#define IMAGE_SUBSYSTEM_EFI_APPLICATION      10  //
#define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER  11   //
#define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER   12  //
#define IMAGE_SUBSYSTEM_EFI_ROM              13
#define IMAGE_SUBSYSTEM_XBOX                 14

// DllCharacteristics Entries

//      IMAGE_LIBRARY_PROCESS_INIT           0x0001     // Reserved.
//      IMAGE_LIBRARY_PROCESS_TERM           0x0002     // Reserved.
//      IMAGE_LIBRARY_THREAD_INIT            0x0004     // Reserved.
//      IMAGE_LIBRARY_THREAD_TERM            0x0008     // Reserved.
#define IMAGE_DLLCHARACTERISTICS_NO_SEH      0x0400     // Image does not use SEH.  No SE handler may reside in this image
#define IMAGE_DLLCHARACTERISTICS_NO_BIND     0x0800     // Do not bind this image.
//                                           0x1000     // Reserved.
#define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER  0x2000     // Driver uses WDM model
//                                           0x4000     // Reserved.
#define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE     0x8000

// Directory Entries

#define IMAGE_DIRECTORY_ENTRY_EXPORT          0   // Export Directory
#define IMAGE_DIRECTORY_ENTRY_IMPORT          1   // Import Directory
#define IMAGE_DIRECTORY_ENTRY_RESOURCE        2   // Resource Directory
#define IMAGE_DIRECTORY_ENTRY_EXCEPTION       3   // Exception Directory
#define IMAGE_DIRECTORY_ENTRY_SECURITY        4   // Security Directory
#define IMAGE_DIRECTORY_ENTRY_BASERELOC       5   // Base Relocation Table
#define IMAGE_DIRECTORY_ENTRY_DEBUG           6   // Debug Directory
//      IMAGE_DIRECTORY_ENTRY_COPYRIGHT       7   // (X86 usage)
#define IMAGE_DIRECTORY_ENTRY_ARCHITECTURE    7   // Architecture Specific Data
#define IMAGE_DIRECTORY_ENTRY_GLOBALPTR       8   // RVA of GP
#define IMAGE_DIRECTORY_ENTRY_TLS             9   // TLS Directory
#define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG    10   // Load Configuration Directory
#define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT   11   // Bound Import Directory in headers
#define IMAGE_DIRECTORY_ENTRY_IAT            12   // Import Address Table
#define IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT   13   // Delay Load Import Descriptors
#define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR 14   // COM Runtime descriptor

//
// Non-COFF Object file header
//

typedef struct ANON_OBJECT_HEADER {
    WORD    Sig1;            // Must be IMAGE_FILE_MACHINE_UNKNOWN
    WORD    Sig2;            // Must be 0xffff
    WORD    Version;         // >= 1 (implies the CLSID field is present)
    WORD    Machine;
    DWORD   TimeDateStamp;
    CLSID   ClassID;         // Used to invoke CoCreateObject
    DWORD   SizeOfData;      // Size of data that follows the header
} ANON_OBJECT_HEADER;

//
// Section header format.
//

#define IMAGE_SIZEOF_SHORT_NAME              8

typedef struct _IMAGE_SECTION_HEADER {
    BYTE    Name[IMAGE_SIZEOF_SHORT_NAME];
    union {
            DWORD   PhysicalAddress;
            DWORD   VirtualSize;
    } Misc;
    DWORD   VirtualAddress;
    DWORD   SizeOfRawData;
    DWORD   PointerToRawData;
    DWORD   PointerToRelocations;
    DWORD   PointerToLinenumbers;
    WORD    NumberOfRelocations;
    WORD    NumberOfLinenumbers;
    DWORD   Characteristics;
} IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;

#define IMAGE_SIZEOF_SECTION_HEADER          40

//
// Resource Format.
//

//
// Resource directory consists of two counts, following by a variable length
// array of directory entries.  The first count is the number of entries at
// beginning of the array that have actual names associated with each entry.
// The entries are in ascending order, case insensitive strings.  The second
// count is the number of entries that immediately follow the named entries.
// This second count identifies the number of entries that have 16-bit integer
// Ids as their name.  These entries are also sorted in ascending order.
//
// This structure allows fast lookup by either name or number, but for any
// given resource entry only one form of lookup is supported, not both.
// This is consistant with the syntax of the .RC file and the .RES file.
//

typedef struct _IMAGE_RESOURCE_DIRECTORY {
    DWORD   Characteristics;
    DWORD   TimeDateStamp;
    WORD    MajorVersion;
    WORD    MinorVersion;
    WORD    NumberOfNamedEntries;
    WORD    NumberOfIdEntries;
//  IMAGE_RESOURCE_DIRECTORY_ENTRY DirectoryEntries[];
} IMAGE_RESOURCE_DIRECTORY, *PIMAGE_RESOURCE_DIRECTORY;

#define IMAGE_RESOURCE_NAME_IS_STRING        0x80000000
#define IMAGE_RESOURCE_DATA_IS_DIRECTORY     0x80000000

typedef struct _TIME_ZONE_INFORMATION {
    LONG Bias;
    WCHAR StandardName[32];
    SYSTEMTIME StandardDate;
    LONG StandardBias;
    WCHAR DaylightName[32];
    SYSTEMTIME DaylightDate;
    LONG DaylightBias;
} TIME_ZONE_INFORMATION, *PTIME_ZONE_INFORMATION, *LPTIME_ZONE_INFORMATION;

/*
 * Message structure
 */
typedef struct tagMSG {
    HWND        hwnd;
    UINT        message;
    WPARAM      wParam;
    LPARAM      lParam;
    DWORD       time;
    POINT       pt;
#ifdef _MAC
    DWORD       lPrivate;
#endif
} MSG, *PMSG, *LPMSG;

#define INVALID_FILE_ATTRIBUTES 0xFFFFFFFF

//==========================================================================
//                      windows function call macro
//==========================================================================

#ifndef DECLSPEC_IMPORT
#define DECLSPEC_IMPORT     __declspec(dllimport)
#endif

#define WINAPI              EXTERN_C DECLSPEC_IMPORT ECode STDAPICALLTYPE
#define WINAPI_(type)       EXTERN_C DECLSPEC_IMPORT type    STDAPICALLTYPE

#define WINUSERAPI          EXTERN_C DECLSPEC_IMPORT ECode STDAPICALLTYPE
#define WINUSERAPI_(type)   EXTERN_C DECLSPEC_IMPORT type    STDAPICALLTYPE

#define WINGDIAPI           EXTERN_C DECLSPEC_IMPORT ECode STDAPICALLTYPE
#define WINGDIAPI_(type)    EXTERN_C DECLSPEC_IMPORT type    STDAPICALLTYPE

#define WINOLEAPI           EXTERN_C DECLSPEC_IMPORT ECode STDAPICALLTYPE
#define WINOLEAPI_(type)    EXTERN_C DECLSPEC_IMPORT type    STDAPICALLTYPE

#define WINOLEAUTAPI        EXTERN_C DECLSPEC_IMPORT ECode STDAPICALLTYPE
#define WINOLEAUTAPI_(type) EXTERN_C DECLSPEC_IMPORT type    STDAPICALLTYPE

#define COINIT_MULTITHREADED 0

#endif //#define _WINTYPE_H_
